package com.bobo.controller;

import cn.hutool.core.bean.BeanUtil;
import com.bobo.base.R;
import com.bobo.pojo.IndexImg;
import com.bobo.pojo.dto.IndexImgDto;
import com.bobo.service.IndexImgService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Tag(name = "首页轮播图接口")
public class IndexImgController {
    @Resource
    private IndexImgService indexImgService;

    @GetMapping("/indexImgs")
    @Operation(summary = "首页轮播图" , description = "获取首页轮播图列表信息")
    public R<List<IndexImgDto>> indexImgs() {
        // 调用IndexImgService的listIndexImg方法获取首页轮播图列表
        List<IndexImg> indexImgList = indexImgService.listIndexImg();
        // 将IndexImg列表转换为IndexImgDto列表
        //使用dto数据
        List<IndexImgDto> indexImgDtos = BeanUtil.copyToList(indexImgList, IndexImgDto.class);
        // 返回成功响应，包含首页轮播图列表
        return R.success(indexImgDtos);
    }
}
